package Week.w149;

import org.junit.Test;

public class Solution01 {

    public int ordinalOfDate(String date) {
        if(date==null){
            return 0;
        }
        String[] array=date.split("-");
        int year=Integer.parseInt(array[0]);
        int month=Integer.parseInt(array[1]);
        int day=Integer.parseInt(array[2]);
        boolean isSpe=isSpe(year);
        int result=0;
        for(int i=1;i<month;i++){
            if(i==1||i==3||i==5||i==7||i==8||i==10||i==12){
                result=result+31;
            }else if(i==2){
                if(isSpe){
                    result=result+29;
                }else {
                    result=result+28;
                }
            }else {
                result=result+30;
            }
        }
        return result+day;
    }

    private boolean isSpe(int year){
        if(year%100==0){
            return year%400==0;
        }
        return year%4==0;
    }
    @Test
    public void test() {
       // date = "2019-01-09"
  System.out.println(ordinalOfDate("2019-02-10"));
    }
}
